package com.wangy.service.impl;

import com.wangy.bean.Role;
import com.wangy.mapper.RoleMapper;
import com.wangy.mapper.RolePermissionMapper;
import com.wangy.mapper.UserRoleMapper;
import com.wangy.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * *@Author yyzb
 * *@Date 2024/10/24 13:07
 * *@Version 1.0
 */

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    RoleMapper roleMapper;

    @Autowired
    UserRoleMapper userRoleMapper;

    @Autowired
    RolePermissionMapper rolePermissionMapper;


    @Override
    public List<Role> getAllRoles() {
        return roleMapper.getAllRoles();
    }

    @Override
    public String getUserRoleName(Long userId) {
        return roleMapper.getUserRoleName(userId);
    }

    @Override
    public void deleteRole(Long roleId) {
        userRoleMapper.deleteByRoleId(roleId);
        rolePermissionMapper.deleteByRoleId(roleId);
        roleMapper.deleteRole(roleId);
    }

    @Override
    public void addRole(String roleName) {
        roleMapper.addRole(roleName);
    }
}
